	package browser.service;

	import java.io.*;
	import java.sql.*;
	import javax.servlet.*;
	import javax.servlet.http.*;
	import org.hibernate.Query;
	import org.hibernate.Session;
	import org.hibernate.SessionFactory;
	import org.hibernate.Transaction;
	import org.hibernate.cfg.Configuration;

	/**
	 * Servlet that will log user out.
	 * The uaccess (user access status) in userinfo will be set to null.
	 */
	public class Logout extends HttpServlet {

		public static Connection conn;
		public static Statement stmt;

		public void doGet(HttpServletRequest request,
				HttpServletResponse response) throws ServletException,
				IOException {

			doPost(request, response);
		}

		public void doPost(HttpServletRequest request,
				HttpServletResponse response) throws ServletException,
				IOException {

			Configuration cfg = new Configuration();
			SessionFactory sessions = cfg.configure().buildSessionFactory();
			Session session = sessions.openSession();
			Transaction tx = session.beginTransaction();

			response.setContentType("text/html");
			PrintWriter out = response.getWriter();

			String[] uid = request.getParameterValues("uid");

			String sql = "update UserInfo set uaccess = null where userid='"
					+ uid[0] + "'";
			Query q = session.createQuery(sql);
			q.executeUpdate();
			tx.commit();
			session.close();

			// response.sendRedirect("/DatabaseBrowser/");
			out.println("<html>");
			out.println("  <head>");
			out.println("    <title>Logout Page</title>");
			out.println("  <link type=\"text/css\" rel=\"stylesheet\" href=\"main.css\"/> </head>");
			out.println("  <body><h2>");
			out.println("<center>");
			out.println("Logged Out!</br> Thank You for Using Database Browser </br>");
			out.println("<a href=\"/DatabaseBrowser/\" target=\"_parent\">Go Back to Log in Page</a>");
			out.println("</center>");
			out.println("</h2></body>");
			out.println("</html>");

		}

	}
